﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WpfApplication2.Helpers
{
    public enum ValidationType
    {
        Requerido,
        Email,
        Telefono,
        MayorIgualCero,
        SoloNumeros
    }

    public class PropertyValidator
    {
        public static bool ValidarRequired(PropertyElement valObject)
        {
            if (string.IsNullOrEmpty(valObject.Value))
            {
                return false;
            }
            return true;
        }

        public static bool ValidarSoloNumeros(PropertyElement valObject)
        {
            if (string.IsNullOrEmpty(valObject.Value))
                return true;
            else
            {
                var numeros = "0123456789";
                var flag = true;
                foreach (Char c in valObject.Value)
                {
                    if (numeros.IndexOf(c) == -1)
                        flag = false;
                }
                return flag;
            }
        }

        public static bool ValidateRequiredString(string valObject)
        {
            if (string.IsNullOrEmpty(valObject))
            {
                return false;
            }
            return true;
        }

        public static bool ValidateMayorIgualCero(PropertyElement valObject)
        {
            try
            {
                var val = Convert.ToInt32(valObject.Value);
                return val >= 0 ? true : false;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }

    public class PropertyElement
    {
        public string Name { get; set; }
        public string Foreground { get; set; }
        public List<ValidationType> Validations { get; set; }
        public bool IsValid
        {
            get;
            set;
        }
        public string Value
        {
            get;
            set;
        }

        public PropertyElement()
        {
            Validations = new List<ValidationType>();
        }
    }
}